import folium
import pandas as pd
import os
from geopy.geocoders import Nominatim

# 定义旅游景点的基本信息
to_csv_name = 'ultimate_sight.csv'
to_csv_path = os.path.join(os.path.abspath(
    os.path.join(os.path.join(os.path.dirname(__file__), ".."), 'test')),
    to_csv_name)
pd_datas = pd.read_csv(to_csv_path).to_dict(orient='record')
# print(pd_datas)
for pd_data in pd_datas:
    print(pd_data)
spots = []
for index in range(1000):
    pd_data = pd_datas[index]
    spot = {
        'name': pd_data['poiName'],
        'location': [pd_data['latitude'], pd_data['longitude']],
        'level': pd_data['sightLevelStr'],
        'price': pd_data['price'],
        'province': pd_data['districtName'] + '市',
        'address': pd_data['distanceStr'],
    }
    spots.append(spot)

# 创建地图对象
m = folium.Map(location=[35, 105], zoom_start=5 ,attr='高德-常规图',tiles="http://webrd02.is.autonavi.com/appmaptile?lang=zh_cn&size=1&scale=1&style=7&x={x}&y={y}&z={z}")

# 添加标记
for spot in spots:
    # 创建标记的HTML内容
    popup_html = f"<div style='width:200px'><strong>{spot['name']}</strong><br>" \
             f"价格: {spot['price']}元<br>" \
             f"级别: {spot['level']}<br>" \
             f"省份: {spot['province']}<br>" \
             f"距离市中心: {spot['address']}</div>"
    # 添加标记
    folium.Marker(location=spot["location"], popup=popup_html).add_to(m)

# 保存地图为html文件
html_name = 'sight_map.html'
html_path = os.path.join(os.path.abspath(
    os.path.join(os.path.join(os.path.dirname(__file__), ".."), 'templates/home')),
    html_name)
m.save(html_path)